/*
 * ViewMainButtonEnabler.java
 */
package trackreggui;

/** Class that handles enabling of buttons in the main GUI
 *
 * @author STKNOLL
 */
public class ViewMainButtonEnabler {
    public enum ButtonEnabling { INITIALIZE, 
        NEW_REGISTRATION,
        OPEN_REGISTRATION,
        CLOSE_REGISTRATION,
        SELECT_ATHLETPOOL,
        SELECT_DISCIPLINPOOL
    }

    private ViewMain mMainView;
    private boolean mHaveRegistration;

    public ViewMainButtonEnabler(ViewMain mMainView) {
        this.mMainView = mMainView;
        mHaveRegistration = false;
    }

    public void enableButtons(ButtonEnabling inEnabling) {
        switch (inEnabling) {
            case INITIALIZE:
                // athlet pool
                mMainView.editAthletButton.setEnabled(false);
                mMainView.removeAthletButton.setEnabled(false);
                mMainView.addAthletToRegistrationButton.setEnabled(false);
                mMainView.removeAthletFromRegistrationButton.setEnabled(false);
                // disciplin pool
                mMainView.editDisciplinButton.setEnabled(false);
                mMainView.removeDisciplinButton.setEnabled(false);
                mMainView.addDisciplinToAthletButton.setEnabled(false);
                mMainView.removeDisciplinFromAthletButton.setEnabled(false);
                // main view buttons
                mMainView.saveButton.setEnabled(false);
                mMainView.printButton.setEnabled(false);
                // menu buttons
                mMainView.saveMenuItem.setEnabled(false);
                mMainView.saveAsMenuItem.setEnabled(false);
                mMainView.printMenuItem.setEnabled(false);
                mMainView.printPreviewMenuItem.setEnabled(false);
                mMainView.closeMenuItem.setEnabled(false);
                // competition tree
                mMainView.competitionTree.setEnabled(false);
                // internal flag
                mHaveRegistration = false;
                break;
            case NEW_REGISTRATION:
            case OPEN_REGISTRATION:
                // main view buttons
                mMainView.saveButton.setEnabled(true);
                mMainView.printButton.setEnabled(true);
                // menu buttons
                mMainView.saveMenuItem.setEnabled(true);
                mMainView.saveAsMenuItem.setEnabled(true);
                mMainView.printMenuItem.setEnabled(true);
                mMainView.printPreviewMenuItem.setEnabled(true);
                mMainView.closeMenuItem.setEnabled(true);
                // competition tree
                mMainView.competitionTree.setEnabled(true);
                // internal flag
                mHaveRegistration = true;
                break;
            case CLOSE_REGISTRATION:
                // main view buttons
                mMainView.saveButton.setEnabled(false);
                mMainView.printButton.setEnabled(false);
                // menu buttons
                mMainView.saveMenuItem.setEnabled(false);
                mMainView.saveAsMenuItem.setEnabled(false);
                mMainView.printMenuItem.setEnabled(false);
                mMainView.printPreviewMenuItem.setEnabled(false);
                mMainView.closeMenuItem.setEnabled(false);
                // competition tree
                mMainView.competitionTree.setEnabled(false);
                // internal flag
                mHaveRegistration = false;
                // disable add remove button
                mMainView.addAthletToRegistrationButton.setEnabled(false);
                mMainView.removeAthletFromRegistrationButton.setEnabled(false);
                mMainView.addDisciplinToAthletButton.setEnabled(false);
                mMainView.removeDisciplinFromAthletButton.setEnabled(false);
                break;
            case SELECT_ATHLETPOOL:
                // athlet pool
                mMainView.editAthletButton.setEnabled(true);
                mMainView.removeAthletButton.setEnabled(true);
                if ( mHaveRegistration == true ) {
                    mMainView.addAthletToRegistrationButton.setEnabled(true);
                    mMainView.removeAthletFromRegistrationButton.setEnabled(true);
                }
                break;
            case SELECT_DISCIPLINPOOL:
                // disciplin pool
                mMainView.editDisciplinButton.setEnabled(true);
                mMainView.removeDisciplinButton.setEnabled(true);
                if ( mHaveRegistration == true ) {
                    mMainView.addDisciplinToAthletButton.setEnabled(true);
                    mMainView.removeDisciplinFromAthletButton.setEnabled(true);
                }
                break;
        }
    }

}
